package com.jml;


import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.nio.charset.Charset;

/**
 * @author:jml
 * @date: 2019/9/23 15:59
 * @description：这个是读取数据的Handler
 */
public class SimpleHandle extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("服务端开始读取数据===============");
        if(msg instanceof ByteBuf){
            ByteBuf req =(ByteBuf)msg;
            //就是UTD-8
            String context = req.toString(Charset.defaultCharset());
            System.out.println(context);
            ctx.channel().writeAndFlush("jjmmll\r\n");
        }
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
    }
}
